package giftmail;

import javax.jms.Destination;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import giftmail.mq.IProducerService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring.xml", 
"classpath:spring-mybatis.xml"})
public class Junit4Gift {
	private static final Logger logger = LoggerFactory.getLogger(Junit4Gift.class);
	
	@Autowired  
    private IProducerService producerService;  
    @Autowired  
    @Qualifier("queueDestination")  
    private Destination destination; 
    @Autowired  
    @Qualifier("sessionAwareQueue")  
    private Destination sessionAwareQueue;
    @Autowired  
    @Qualifier("adapterQueue")  
    private Destination messageListenerAdapterQueue; 
    
	/**
	 * 测试MessageListener
	 */
	@Test  
    public void testSend() {  
        for (int i=0; i<2; i++) {  
            producerService.sendMessage(destination, "你好，生产者！这是消息：" + (i+1));  
        }  
    }  
	
	/**
	 * 测试SessionAwareMessageListener
	 */
	@Test  
    public void testSessionAwareMessageListener() {  
        producerService.sendMessage(sessionAwareQueue, "测试SessionAwareMessageListener");  
    } 
	
	/**
	 * 测试MessageListenerAdapter
	 */
	@Test  
    public void testMessageListenerAdapter() {  
        producerService.sendMessage(messageListenerAdapterQueue, "测试MessageListenerAdapter");  
    }
	
	
}
